package com.kedou.sdk.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.kedou.sdk.JuHaoWanSDK;
import com.kedou.sdk.core.HttpEngineApi;
import com.kedou.sdk.params.bean.AgreementModel;


public class PrivateActivity extends AppBaseActivity implements View.OnClickListener {



//    ImageView imageView;
//
    ImageView closeView;
    private TextView mWebClientView;
    private TextView userText,privateText;
    private Button cancelBtn,ConfirmBtn;
    private AgreementModel model;
    private boolean isUser = true;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutIdentifier("activity_private"));
        model = getIntent().getParcelableExtra("data");
        userText = findViewById(getViewIdentifier("private_user"));
        userText.setOnClickListener(this);
        privateText = findViewById(getViewIdentifier("private_private"));
        privateText.setOnClickListener(this);
        closeView =   findViewById(getViewIdentifier("activity_bindphone_finish_btn"));
        closeView.setOnClickListener(this);
        cancelBtn =   findViewById(getViewIdentifier("private_cancel"));
        cancelBtn.setOnClickListener(this);
        ConfirmBtn =   findViewById(getViewIdentifier("private_ok"));
        ConfirmBtn.setOnClickListener(this);

        mWebClientView = findViewById(getViewIdentifier("private_webview"));
//        WebSettings webSettings = mWebClientView.getSettings();
//        webSettings.setUseWideViewPort(true);
//        webSettings.setSupportZoom(true);
//        webSettings.setAppCacheEnabled(false);
//        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
//        webSettings.setJavaScriptEnabled(true);
//        webSettings.setDomStorageEnabled(true);
//        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
//        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
//        mWebClientView.loadData(model.getUserAgreement(), "text/html", "UTF-8");
        mWebClientView.setText(Html.fromHtml(model.getUserAgreement()));
    }

    @Override
    public void onClick(View view) {
        if(view==closeView||view ==cancelBtn){
            android.os.Process.killProcess(android.os.Process.myPid());
            finish();
        }else if (view == ConfirmBtn){
            HttpEngineApi.getInstance().getEngineConduits().writeAgreePrivate();
            JuHaoWanSDK.getInstance().initPrivate();
            finish();
        }else if(view == userText){
            if(!isUser){
                isUser = true;
                ((ScrollView)(mWebClientView.getParent())).scrollTo(0,0);
                userText.setTextColor(Color.parseColor("#8FC31F"));
                userText.setTextSize(18);
                mWebClientView.setText(Html.fromHtml(model.getUserAgreement()));
//                mWebClientView.loadData(model.getUserAgreement(), "text/html", "UTF-8");
                privateText.setTextSize(15);
                privateText.setTextColor(Color.parseColor("#ffffffff"));
            }
        }else if (view == privateText){
            if(isUser){
                isUser = false;
                ((ScrollView)(mWebClientView.getParent())).scrollTo(0,0);
                userText.setTextColor(Color.parseColor("#ffffffff"));
                userText.setTextSize(15);
                mWebClientView.setText(Html.fromHtml(model.getPrivacyAgreement()));
//                mWebClientView.loadData(model.getPrivacyAgreement(), "text/html", "UTF-8");
                privateText.setTextSize(18);
                privateText.setTextColor(Color.parseColor("#8FC31F"));
            }
        }
    }

    @Override
    protected void onDestroy() {
//        HttpEngineConduits wanSDKDataDao = HttpEngineApi.getInstance().getEngineConduits();
//        NoticePopup popup=wanSDKDataDao.getPlatformConfigInfo().getNotice_popup();
//        if(popup!=null){
//            Intent in = new Intent(PrivateActivity.this,NoticeActivity.class);
//            in.putExtra("pop",popup);
//            startActivity(in);
//        }
//
        super.onDestroy();
    }
}
